;(function($){
    /**
	 * 初始化字典类型下拉框，使用方式：select标签增加 dict-type 属性，值为系统字典的类型，s-value属性是想要默认选中的选项值
	 * <select id="type" dict-type="supplier_type" s-value="" name="type" class="form-control"></select>
	 *
     * @param content
     */
    $.fn.initFormDictSelect=function(){
        var dictSelectArray = $(this).find('select[dict-type]');
        $.each(dictSelectArray,function (index,selectDom) {
            var dictType = $(selectDom).attr('dict-type');
            var dictList = getDictTypeFromLocalStorage(dictType);

            var value = $(selectDom).val();
            if(!value){
                value = $(selectDom).attr('s-value');
            }

            if(dictList){
                $.each(dictList,function (dindex,dict) {
                    $(selectDom).append("<option value='"+dict.value+"'>"+dict.name+"</option>");
                });
            }

            if (value){
                $(selectDom).val(value);
            }
        });
    }

    $.fn.initDictSelect=function(extraLabel,extraValue,clearOptions){
        var _this = this;
        var dictType = $(_this).attr('dict-type');
        var dictList = getDictTypeFromLocalStorage(dictType);

        var value = $(_this).val();
        if(!value){
            value = $(_this).attr('s-value');
        }

        if(clearOptions===true){
            $(_this).empty();
        }

        if(extraLabel){
            $(_this).append("<option value='"+extraValue+"'>"+extraLabel+"</option>");
        }

        if(dictList){
            $.each(dictList,function(dindex,dict) {
                $(_this).append("<option value='"+dict.value+"'>"+dict.name+"</option>");
            });
        }

        if (value){
            $(_this).val(value);
        }
    }
})(jQuery);